﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Windows.Forms;

public class AppConfig:Singleton<AppConfig>
{
    public AppConfig()
    {
        if (!LoadConfig())
        {
            TcpPort = "0";
            UdpPort = "0";
        }
    }

    public bool LoadConfig()
    {
        string strConfigPath = Path.Combine(Application.StartupPath, configFile);
        if (!File.Exists(strConfigPath))
        {
            return false;
        }
        using (StreamReader r = new StreamReader(strConfigPath))
        {
            TcpPort = r.ReadLine();
            UdpPort = r.ReadLine();
        }
        return true;
    }

    public bool SaveConfig()
    {
        if (File.Exists(configFile))
        {
            File.SetAttributes(configFile, FileAttributes.Normal);
        }

        StreamWriter w = File.CreateText(configFile);

        w.WriteLine(TcpPort);
        w.WriteLine(UdpPort);
        w.Close();
        return true;
    }

    const String configFile = "ServerConfig.cfg";
    public String TcpPort { get; set; }
    public string UdpPort { get; set; }

}
